<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\shusy_hotel\Entity\ShusyHotel;

class HotelItemDetail extends HotelItem {

  protected function setValue() {
    parent::setValue();
    $value = [
      'rooms' => $this->getRooms($this->entity),
    ];
    $this->merge($value);
  }

  protected function getRooms(ShusyHotel $hotel) {
    $list = [];
    $query = db_select('shusy_hotel_room', 'r');
    $query->fields('r', ['id']);
    $query->condition('hotel_id', $hotel->id);
    $query->condition('status', 1);
    $query->orderBy('id');
    $result = $query->execute();
    while ($row = $result->fetchAssoc()) {
      $list[] = HotelRoomItem::init($row['id']);
    }
    return $list;
  }
}
